package com.weasel.im.common.codec;

import com.weasel.im.common.domain.Message;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

import java.nio.charset.Charset;

/**
 * Created by Dylan on 2015/11/27.
 */
public class MessageEncoder extends MessageToByteEncoder<Message> {


    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Message message, ByteBuf byteBuf) throws Exception {
        String str = byteBuf.toString(Charset.defaultCharset());
        byteBuf.writeBytes(message.toJson().getBytes(Charset.defaultCharset()));
    }

}
